package com.ithanwen.controller;

import com.ithanwen.pojo.Clazz;
import com.ithanwen.pojo.ClazzQueryParam;
import com.ithanwen.pojo.PageResult;
import com.ithanwen.pojo.Result;
import com.ithanwen.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created By tony
 * <br/>Date: 2025/7/14 15:52
 * <br/>Description:
 */
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    //分页查询
    @RequestMapping(value = "/clazzs",method = RequestMethod.GET)
    public Result list(ClazzQueryParam clazzQueryParam)
    {
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }
    //根据id删除
    @RequestMapping(value = "/clazzs/{id}",method = RequestMethod.DELETE)
    public Result deleteClazz(@PathVariable("id") Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }
    //添加班级
    @RequestMapping(value = "/clazzs",method = RequestMethod.POST)
    public Result addClazz(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }
    //根据id查询班级
    @RequestMapping(value = "/clazzs/{id}",method = RequestMethod.GET)
    public Result getById(@PathVariable Integer id){
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }

    //修改班级
    @RequestMapping(value = "/clazzs",method = RequestMethod.PUT)
    public Result updateClazz(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    //查询所有班级
    // @RequestMapping(value = "/clazzs/list",method = RequestMethod.GET)
    // public Result getList(){
    //     return Result.success(clazzService.findall());
    // }
}